﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using XbsWebAPI.EntityFrameworkCore;
using XbsWebAPI.EntityFrameworkCore.Entities.Detailed;

namespace XbsWebAPI.Core.Repositories.Detaileds
{
    public class DetailedRepository : IDetailedRepository
    {
        private readonly DataContext _dataContext;

        public DetailedRepository(DataContext dataContext)
        {
            _dataContext = dataContext;
        }

        public IQueryable<Detailed> AsQueryable()
        {
            return _dataContext.Detaileds.AsQueryable();
        }

        public Detailed Create(Detailed entity)
        {
            //应该要通过订单号去查询订单表
            //如果订单状态为已确认，则收支明细表的交易类型字段为收入
            //如果订单状态为退款，则收支明细的交易类型字段为退款
            if (entity == null)
                return null;
            entity.Id = Guid.NewGuid();
            entity.CreationDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            entity.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            _dataContext.Detaileds.Add(entity);
            int save = _dataContext.SaveChanges();
            if (save <= 0)
                return null;
            return entity;
        }

        public Task<Detailed> CreateAsync(Detailed entity)
        {
            return Task.FromResult(Create(entity));
        }

        public Detailed Delete(Guid id)
        {
            throw new NotImplementedException();
        }

        public Task<Detailed> DeleteAsync(Guid id)
        {
            throw new NotImplementedException();
        }

        public IQueryable<Detailed> Query(Expression<Func<Detailed, bool>> filter)
        {
            throw new NotImplementedException();
        }

        public Detailed QueryById(Guid id)
        {
            throw new NotImplementedException();
        }

        public Detailed Update(Detailed entity)
        {
            throw new NotImplementedException();
        }

        public Task<Detailed> UpdateAsync(Detailed entity)
        {
            throw new NotImplementedException();
        }
    }
}
